package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-05 10:26
 */
public class Solution_0172 {
    /**
     * 阶乘后的零
     *
     * @param n
     * @return
     */
    public int trailingZeroe1s(int n) {

        if (n == 0) {
            return 0;
        }
        /**
         *
         */
        int res = 1;
        for (int i = 0; i <= n; i++) {
            res = res * i;
        }
        double dTen = 10;
        int ITen = 10;
        int zero = 0;
        while (res / dTen == (double) res / 10) {
            zero++;
            dTen = dTen * 10;
            ITen = ITen * 10;
        }
        return zero;
    }

    /**
     * 时间复杂度不对
     *
     * @param n
     * @return
     */
    public int trailingZeroes(int n) {
        if (n == 0) {
            return 0;
        }
        int res = 1;
        for (int i = 0; i <= n; i++) {
            res = res * i;
        }

        int zero = 0;
        while (res % 10 == 0) {
            zero++;
            res = res / 10;

        }
        return zero;
    }

    /**
     * 统计5的数量
     *
     * @param n
     * @return
     */
    public int trailingZeroes1(int n) {
        int count = 0;
        while (n >= 5) {
            count += n / 5;
            n /= 5;
        }
        return count;
    }

    public static void main(String[] args) {
        Solution_0172 solution_0172 = new Solution_0172();
        solution_0172.trailingZeroes1(30);
    }
}
